{% extends './layout.tpl' %}
{% block css_assets %}
{% endblock %}

{% block content %}

	<div class="layadmin-user-login-main">
		<div class="layadmin-user-login-box layadmin-user-login-header">
			<h2>找回密码</h2>
			<p></p>
		</div>
		<div class="layadmin-user-login-box layadmin-user-login-body layui-form">
			<form class="layui-form" action="">
				<div class="layui-form-item">
					<label class="layadmin-user-login-icon iconfont icon-youxiang" for="user-login-username"></label>
					<input type="text" id="mobile" name="mobile"  lay-verify="mobile" placeholder="请输入注册的手机号" class="layui-input">
				</div>
                <div class="layui-form-item">

                        <div class="layui-col-md8">
                            <input type="text" name="verify_code" lay-verify="verify_code" autocomplete="off"
                                   placeholder="短信验证码" class="layui-input">
                        </div>
                        <div >
                            <input type="button" class="layui-btn" lay-submit="" lay-filter="sendSMS" value="获取验证码"/>
                        </div>
                </div>
				<div class="layui-form-item mt30">
					<button class="layui-btn layui-btn-fluid" lay-submit="" id="sendEmailBut" lay-filter="user-login-submit">发送短信, 重置密码</button>
				</div>
			</form>
		</div>
	</div>

{% endblock %}



{% block js_assets %}


	<script>
        layui.use(['form', 'layedit', 'laydate'], function(){
            var form = layui.form
                ,layer = layui.layer
            form.verify({
                mobile : function(value){
                    var reg=/^1[3|4|5|7|8][0-9]{9}$/;
                    if(!reg.test(value)){
                        return '手机号码格式有误';
                    }
                },
            });
            //监听提交
            form.on('submit(user-login-submit)', function(data){
                submit(data.field)
                return false;
            });
            //监听提交
            form.on('submit(sendSMS)', function(data){
                sendSMS()
                return false;
            });

        });

        function submit(data){
            $.post("/sale/login/password/retrieve",data,function(result){
                if(result.status !=200){
                    layer.msg(result.msg,{icon:2});
                    return false
                }
                setTime();
                layer.msg("重置密码短信发送成功，请查收",{icon:1})
                window.location.href="/sale/password/retrieve/reset";
            });
        }
        var countdown = 60;
        function setTime() {
            var val = $("#sendEmailBut");
            if (countdown == 0) {
                val.removeClass("layui-btn-disabled");
                val.removeAttr("disabled");
                val.html("发送短信, 重置密码");
                countdown = 60;
            } else {
                val.addClass("layui-btn-disabled");
                val.attr("disabled", true);
                val.html("重新发送(" + countdown + ")");
                countdown--;
                setTimeout(function() {
                    setTime();
                },1000)
            }
        }
        //发送验证码
        function sendSMS() {
            var mobile = $("#mobile").val();
            $.ajax({
                url: "/common/send_sms",
                async: true,
                data: {mobile: mobile},
                type: "post",
                dataType: "json",
                contentType: "application/x-www-form-urlencoded;charset=utf-8",
                success: function (data) {
                    if (data.status == 200) {
                        layer.msg("短信发送成功，请注意查收", {icon: 1, time: 1000,})
                    }
                },
                error: function (jqXHR, textStatus, errorThrown) {
                }
            });
        }
	</script>
{% endblock %}


